/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2025-06-00     YTR       the first version
 */


#define DBG_TAG "rt_uart2"
#define DBG_LVL DBG_LOG

#include "main.h"

#include "all.h"

struct serial_configure uart2_configs = RT_SERIAL_CONFIG_DEFAULT;
struct rt_semaphore sem2;
rt_device_t u2_dev;

rt_err_t uart2_rx_callback(rt_device_t dev,rt_size_t size){
    char buffer;
    rt_device_read(u2_dev, 0, &buffer, 1);
    return RT_EOK;
}
void uart2_init(void){

    u2_dev = rt_device_find("uart2");
    rt_err_t ret = 0;
    if(u2_dev == RT_NULL){
        LOG_E("rt_device_find[uart2] failed....\n");
    }
    else{
        LOG_D("rt_device_find[uart2] success\n");
        ret = rt_device_open(u2_dev, RT_DEVICE_FLAG_INT_RX);
        if(ret<0){
            LOG_E("rt_device_open[uart2] failed....\n");
        }
        else{

            rt_device_control(u2_dev, RT_DEVICE_CTRL_CONFIG, (void *)&uart2_configs);

            rt_sem_init(&sem2,"u2_rx_sem2",0,RT_IPC_FLAG_FIFO);

            rt_device_set_rx_indicate(u2_dev, uart2_rx_callback);

        }
    }
}





